import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main4 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        for (int i = 0; i < n; i++) {
            b[i] = in.nextInt();
        }
        int q = in.nextInt();
        // 新数组
        List<Integer> arr = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < b[i]; j++) {
                arr.add(a[i]);
            }
        }

        // 询问
        for (int i = 0; i < q; i++) {
            int ret = 0;
            int l = in.nextInt(), r = in.nextInt();
            for (int j = l - 1; j <= r - 1; j++) {
                ret += arr.get(j);
            }
            System.out.println(ret);
        }
    }
}
